package com.example.mountCard.controller;

import com.example.entity.MonthCard;
import com.example.mountCard.service.MonthCardService;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import com.example.utils.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/month")
public class MonthCardController {
    @Autowired
    MonthCardService monthCardService;
    /**
     * 停车场管理-月卡全查
     * @return
     */
    @GetMapping("/getMonthCard")
    public CommonResult getMonthCard(String monthCardCode,Integer pageSize,Integer pageNum){
        PageRequest pageRequest = new PageRequest();
        pageRequest.setPageSize(pageSize);
        pageRequest.setPageNum(pageNum);
        MyPageHelper.StartPage(pageRequest);
        CommonResult commonResult = monthCardService.getMonthCard(monthCardCode);
        return commonResult;
    }
    /**
     * 停车场管理-月卡删除
     */
    @DeleteMapping("/delMonthCard")
    public CommonResult delMountCard(Integer id){
        int i = monthCardService.delMonthCard(id);
        return CommonResult.ok(i);
    }
    /**
     * 停车场管理-月卡增改
     */
    @PostMapping("saveOrUpdateMonth")
    public CommonResult saveOrUpdateMonth(@RequestBody MonthCard monthCard){
        int i = monthCardService.saveOrUpdateMonth(monthCard);
        if(i>0){
            return CommonResult.ok();
        }else{
            return CommonResult.fail();
        }
    }
}
